LD += -m elf_x86_64
LD_FLAGS := -Ttext 0x0 -s --oformat binary
DEBUG_FLAGS := -g -ggdb -O0

image : linux.img

linux.img : build bootsect setup system
	./build bootsect setup system > $@

build : tools/build.c
	gcc $(DEBUG_FLAGS) -o $@ $<

bootsect : bootsect.o
	$(LD) $(LD_FLAGS) -o $@ $<
bootsect.o: bootsect02.S
	$(AS) $< -o $@
# linux.img: bootsect.o
# 	$(LD) $(LD_FLAGS) -o $@ $<

setup : setup.o
	$(LD) $(LD_FLAGS) -e _start_setup -o $@ $<
setup.o : setup01.S 
	$(AS) -o $@ $<

system : kernel/head.S kernel/*.c mm/*.c kernel/blk_drv/*.c
	cd kernel; make system; mv system ../; cd ..

.PHONY: clean
clean:
	rm *.o
	if [ -e setup ]; then rm setup; fi
	if [ -e bootsect ]; then rm bootsect; fi
	if [ -e build ]; then rm build; fi
	if [ -e linux.img ]; then rm linux.img; fi
	
